This repository was archived by the owner on Apr 26, 2026. It is now read-only.
Add scripts/ importer for Claude Code sessions into OpenCode DB#14
Open
Aptul9 wants to merge 1 commit into
Open
Add scripts/ importer for Claude Code sessions into OpenCode DB#14Aptul9 wants to merge 1 commit into
Aptul9 wants to merge 1 commit into
Conversation
Python script that reads ~/.claude/projects/*/\*.jsonl and inserts the conversations into the OpenCode SQLite database so they become visible in the UI. Interactive REPL: type a keyword to filter by title / first prompt / cwd, then a number to import. Handles custom-title events (chats renamed from the Claude Code UI), groups events into turns, remaps tool names to the opencode conventions used by tool-mapping.ts, and uses the per-turn max usage to avoid the double-count bug that would otherwise inflate the context counter. Falls back to the 'global' project when the jsonl cwd does not match any opencode project worktree; session.directory still preserves the original path so the chat appears under the correct folder in the UI.
Closed
9 tasks
17 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Python script that reads
~/.claude/projects/*/*.jsonl(Claude Code CLI session history) and inserts the conversations into the OpenCode SQLite database, so previously-used Claude Code sessions become visible in the OpenCode UI.Lives under
scripts/and does not touch any plugin source. Opt-in tool.Features
last N), batch selection (1 3 5,1-5,all)custom-titleevents so chats renamed from the Claude Code UI keep their title after importsrc/tool-mapping.ts(Edit/Write/Bash/... → lowercase;mcp__server__tool→server_tool; internal CLI tools are skipped)cwdagainst OpenCodeproject.worktree; falls back to theglobalproject when no match exists (session.directory still reflects the original cwd so the chat appears under the correct folder in the UI)max()aggregation for token usage, mirroring the runtimelastIterationUsage()behavior to avoid inflating cumulative countsPreserved
User prompts, assistant text and reasoning (thinking), tool calls with input/output (matched by
tool_use_id), per-turn token totals, chronological order.Not preserved
Images and binary attachments, sub-agent chains (
isSidechain: true), thinking signatures, real git snapshot hashes (placeholder000...000).Requirements
sqlite3), no external depsTest plan
.jsonlsession: session, message, and part rows correctly created; reasoning, text, and tool calls visible in the UIcustom-titlechats render with the user-chosen title in OpenCodeglobalworks for folders that have no dedicated OpenCode projectDocs: see
scripts/README.md.Split from a previous combined PR per maintainer request. Purely additive (new files under
scripts/), does not modify any existing source.